package org.lcx.pipeline.impl;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.text.MessageFormat;

/**
 * pipeline公共方法的
 */
public class PipelineConfig {
	public static final Log LOG = LogFactory.getLog(PipelineConfig.class);

	/**
	 * 获取事务定义<BR>
	 * 默认为REQUIRED
	 */
	public static int getTransactionMode(String transaction) {
		if (null == transaction || "".equals(transaction)) {
			return 0;
		}
		String transactionStr = transaction.substring(3).toUpperCase();
		if ("REQUIRED".equals(transactionStr)) {
			return 0;
		} else if ("SUPPORTS".equals(transactionStr)) {
			return 1;
		} else if ("MANDATORY".equals(transactionStr)) {
			return 2;
		} else if ("REQUIRED_NEW".equals(transactionStr)) {
			return 3;
		} else if ("NOT_SUPPORTED".equals(transactionStr)) {
			return 4;
		} else if ("NEVER".equals(transactionStr)) {
			return 5;
		} else if ("NESTED".equals(transactionStr)) {
			return 6;
		}
		String msgFormat = "无效的transaction({0}),将默认启用REQUIRED模式";
		LOG.error(MessageFormat.format(msgFormat, transaction));
		return 0;
	}
}
